package com.example.tellwin.mine.presenter;

import android.text.TextUtils;

import com.apkfuns.logutils.LogUtils;
import com.example.tellwin.MainApplication;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.home.bean.ContentBean;
import com.example.tellwin.mine.bean.WeChatPayBean;
import com.example.tellwin.mine.contract.RechargeContract;
import com.example.tellwin.utils.HttpUtils;
import com.example.tellwin.utils.ToastUtil;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/12/1
 * @Describe ：
 **/
public class RechargePresenter extends RxPresenter<RechargeContract.View> implements RechargeContract.Presenter<RechargeContract.View> {

    private TwjfApi mApi;

    private int pages;
    private int pageNum;
    private final int pageSize = 10;
    private boolean isNotMore = true;

    @Inject
    public RechargePresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void chargeMoney(String money ,int type) {
        RequestBody requestBody = HttpUtils.getRequestBody("rechargeMoney", money, "payType", type + "");
        mApi.recharge(requestBody, new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                if (type == 1) {
                    WeChatPayBean weChatPayBean = contentBean.getWxPayMap();
                    LogUtils.e(weChatPayBean);
                    if(weChatPayBean == null){
                        ToastUtil.show(MainApplication.getContext() , "获取微信参数失败");
                        return;
                    }
                    mView.chargeMoneyWeChat(contentBean.getPayId() ,weChatPayBean);
                } else if (type == 2) {
                    if(contentBean.getZfbPayMap()!=null&&!TextUtils.isEmpty(contentBean.getZfbPayMap().data)){
                        mView.chargeMoneyAli(contentBean.getZfbPayMap().data);
                    }else {
                        ToastUtil.show(MainApplication.getContext() , "获取支付宝参数失败");
                        return;
                    }
                } else if (type == 3) {

                }
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void payQuery(String payId ,int type) {
        mApi.payQuery(payId , type+"", new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                if (type == 1) {
                   if(contentBean.getResultMap()!=null&&contentBean.getResultMap().isSuccess()){
                       mView.payQuerySuccess();
                   }
                } else if (type == 2) {

                } else if (type == 3) {

                }
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
